package com.sunny.leetcode;

import java.util.LinkedList;

/**
 * @author Sunny
 * @date 2020/8/3
 */
public class Main {

    public static void main(String[] args) {
        System.out.println(test("abcde", "abced"));
    }

    /**
     * 错误  有问题
     *
     * @param a
     * @param b
     * @author Sunny
     * @date 2020/8/3
     */
    public static String test(String a, String b){
        if (a == null || b == null) {
            return "False";
        }

        if (a.length() != b.length()) {
            return "False";
        }

        LinkedList<Character> queue = new LinkedList<>();
        for (int i = 0; i < a.length(); i++) {
            char c = a.charAt(i);
            queue.offer(c);
        }

        int size = b.length();
        int count = 0;
        for (int i = 0; i < size; i++) {
            Character c = queue.pollFirst();
            char bc = b.charAt(i);
            if (c == bc) {
                count++;
            } else {
                if (queue.isEmpty()) {
                    break;
                }
                queue.addLast(c);
                i--;
            }
        }

        if (count == size) {
            return "True";
        }

        return "False";
    }

}
